package org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.persistence;

import jakarta.annotation.Resource;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.proxy.per.day.flow.LazyProxyPerDayFlow;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.proxy.per.day.flow.LazyProxyPerDayFlowRepository;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.converter.LazyProxyPerDayFlowConverter;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.infrastructure.entity.LazyProxyPerDayFlowDO;
import org.springframework.stereotype.Repository;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;

import java.util.List;
import java.util.stream.Collectors;

/**
 * describe 每日统计代理流量
 *
 * @author Jia wei Wu
 * @date 2025/06/06 11:39 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence
 **/
@Repository
public class LazyProxyPerDayFlowRepositoryImpl implements LazyProxyPerDayFlowRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增每日统计代理流量
     *
     * @param lazyProxyPerDayFlow 新增每日统计代理流量
     * @return {@link Result<LazyProxyPerDayFlow>} 每日统计代理流量新增后领域对象
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<LazyProxyPerDayFlow> story(LazyProxyPerDayFlow lazyProxyPerDayFlow) {
        LazyProxyPerDayFlowDO lazyProxyPerDayFlowDO = LazyProxyPerDayFlowConverter.INSTANCE.fromLazyProxyPerDayFlow(lazyProxyPerDayFlow);
        lazyLambdaStream.upsert(lazyProxyPerDayFlowDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增每日统计代理流量
     *
     * @param lazyProxyPerDayFlowList 批量新增每日统计代理流量
     * @return {@link Result<List<LazyProxyPerDayFlow>>} 每日统计代理流量新增后领域对象集合
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<List<LazyProxyPerDayFlow>> batchStory(List<LazyProxyPerDayFlow> lazyProxyPerDayFlowList) {
        List<LazyProxyPerDayFlowDO> lazyProxyPerDayFlowDOList = lazyProxyPerDayFlowList.stream().map(LazyProxyPerDayFlowConverter.INSTANCE::fromLazyProxyPerDayFlow).collect(Collectors.toList());
        lazyLambdaStream.upsert(lazyProxyPerDayFlowDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个每日统计代理流量
     *
     * @param lazyProxyPerDayFlow 查询单个每日统计代理流量
     * @return {@link Result<LazyProxyPerDayFlow>} 每日统计代理流量领域对象
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<LazyProxyPerDayFlow> findOne(LazyProxyPerDayFlow lazyProxyPerDayFlow) {
        LazyProxyPerDayFlowDO lazyProxyPerDayFlowDO = LazyProxyPerDayFlowConverter.INSTANCE.fromLazyProxyPerDayFlow(lazyProxyPerDayFlow);
        LazyProxyPerDayFlow lazyProxyPerDayFlowOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(lazyProxyPerDayFlowDO), LazyProxyPerDayFlow.class);
        return ResultFactory.successOf(lazyProxyPerDayFlowOne);
    }

    /**
     * describe 查询多个每日统计代理流量
     *
     * @param lazyProxyPerDayFlow 查询多个每日统计代理流量
     * @return {@link Result<List<LazyProxyPerDayFlow>>} 每日统计代理流量领域对象
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<List<LazyProxyPerDayFlow>> findList(LazyProxyPerDayFlow lazyProxyPerDayFlow) {
        LazyProxyPerDayFlowDO lazyProxyPerDayFlowDO = LazyProxyPerDayFlowConverter.INSTANCE.fromLazyProxyPerDayFlow(lazyProxyPerDayFlow);
        List<LazyProxyPerDayFlow> lazyProxyPerDayFlowList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(lazyProxyPerDayFlowDO), LazyProxyPerDayFlow.class);
        return ResultFactory.successOf(lazyProxyPerDayFlowList);
    }

    /**
     * describe 分页查询多个每日统计代理流量
     *
     * @param size                当前页数
     * @param current             当前页
     * @param lazyProxyPerDayFlow 分页查询多个每日统计代理流量
     * @return {@link Result<LazyPage<LazyProxyPerDayFlow>>} 分页每日统计代理流量领域对象
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<LazyPage<LazyProxyPerDayFlow>> findPage(int size, int current, LazyProxyPerDayFlow lazyProxyPerDayFlow) {
        LazyProxyPerDayFlowDO lazyProxyPerDayFlowDO = LazyProxyPerDayFlowConverter.INSTANCE.fromLazyProxyPerDayFlow(lazyProxyPerDayFlow);
        LazyPage<LazyProxyPerDayFlow> lazyPage = new LazyPage<>(current, size);
        LazyPage<LazyProxyPerDayFlow> lazyProxyPerDayFlowLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(lazyProxyPerDayFlowDO), lazyPage, LazyProxyPerDayFlow.class);
        return ResultFactory.successOf(lazyProxyPerDayFlowLazyPage);
    }

    /**
     * describe 删除每日统计代理流量
     *
     * @param lazyProxyPerDayFlow 删除每日统计代理流量
     * @return {@link Result<LazyProxyPerDayFlow>} 每日统计代理流量
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<LazyProxyPerDayFlow> remove(LazyProxyPerDayFlow lazyProxyPerDayFlow) {
        LazyProxyPerDayFlowDO lazyProxyPerDayFlowDO = LazyProxyPerDayFlowConverter.INSTANCE.fromLazyProxyPerDayFlow(lazyProxyPerDayFlow);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(lazyProxyPerDayFlowDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在每日统计代理流量
     *
     * @param lazyProxyPerDayFlow 每日统计代理流量领域对象
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在
     * @author Jia wei Wu
     * @date 2025/06/06 11:39 晚上
     **/

    @Override
    public Result<Boolean> exists(LazyProxyPerDayFlow lazyProxyPerDayFlow) {
        LazyProxyPerDayFlowDO lazyProxyPerDayFlowDO = LazyProxyPerDayFlowConverter.INSTANCE.fromLazyProxyPerDayFlow(lazyProxyPerDayFlow);
        Boolean exists = lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(lazyProxyPerDayFlowDO));
        return ResultFactory.successOf(exists);
    }

}